<?php
class MiscUtils {
  public static function dump($obj, $what = NULL) {
    if (defined ('DEBUG_ENABLED') && ! DEBUG_ENABLED) {
      return;
    }
    echo "<pre>\n";
    if (is_null ($obj)) {
      echo ($what !== NULL) ? "$what=!NULL!" : '!NULL!';
    } else if ($obj === '') {
      echo ($what !== NULL) ? "$what=!EMPTY!" : '!EMPTY!';
    } else if ($obj === false) {
      echo ($what !== NULL) ? "$what=!FALSE!" : '!FALSE!';
    } else {
      if ($what !== NULL) {
        echo "$what=<br>";
      }
      echo htmlspecialchars (print_r ($obj, true));
    }
    echo "</pre>\n";
  }
  
  public static function getParam($itm, $default = '', $trimText = false) {
  	
    if (isset($_POST[$itm])) {
    	//echo '1-' . $_POST[$itm];
      return ($trimText) ? trim($_POST[$itm]) : $_POST[$itm];
    } else if (isset($_GET[$itm])) {
    	//echo '2-' . $_GET[$itm];
      return ($trimText) ? trim($_GET[$itm]) : $_GET[$itm];
    } else {
    	//echo 'sss';
      return $default;
    }
  }
  
  public static function encode($obj) {
    if ($obj) {
      $item = urlencode(urlencode($obj));
    }
    return $item;
  }
  public static function unique() {
    $unique = 'u' . (mktime() * rand());
    return $unique;
  }
  
  public static function autopwd() {
    $unique = substr(mktime() * rand(),0,4);
    return $unique;
  }

}
?>